layui.use(['form', 'jquery', 'layer'], function () {
    var form = layui.form,
        $ = layui.jquery,
        layer = layui.layer;   //默认启用

    var laydate = layui.laydate;

    laydate.render({
        elem: '#applicationTime', //指定元素
        type: 'datetime',
        fullPanel: true
    });
    form.render()

    form.on("submit(addUser)", function (data) {
        var loadIndex = layer.load(2, {
            shade: [0.3, '#333']
        });

        $.ajax({
                type: "POST",
                url: "/request/insertWaveRequestDetail",
                dataType: "json",
                contentType: "application/json",
                data: JSON.stringify(data.field),
                success: function (res) {
                    layer.close(loadIndex);
                    if (res.code === 0) {
                        parent.layer.msg("采购申请添加成功!", {time: 1500}, function () {
                            //刷新父页面
                            parent.location.reload();
                        });
                    } else {
                        layer.msg(res.msg);
                    }
                }
            });
        return false
    });

    form.on('switch(adminUser)', function (data) {
        $("#adminUser").val(data.elem.checked);
    });

    form.on('switch(locked)', function (data) {
        $("#locked").val(data.elem.checked);
    });

});